package cn.shadow.service;

import cn.shadow.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public class AccountService implements Runnable {

    public AccountService() {
        this.run();
        System.out.println("000000000000000");
    }

    @Override
    public void run() {
        while (true) {
            //mian线程会一直卡死这里
        }
    }

    @Autowired
    AccountMapper mapper;

    @Autowired
    DataSourceTransactionManager transactionManager;

    @Transactional(rollbackFor = MyException.class)
    public void transfer() throws MyException {
        mapper.changeNum(500, "1");
        mapper.changeNum(-500, "2");
    }


}
